import Vue from 'vue'
import Router from 'vue-router'
import MainRouter from './mainRouter'
import store from '../store/index.js';

Vue.use(Router)

const router = new Router({
	routes: MainRouter
});


router.beforeEach((to, from, next) => {
  console.log('to',to)
  var routerObject = {
    fullPath: to.fullPath,
    params: to.params,
    query: to.query,
  };
	if (to.meta.clearFullPath) {
		routerObject.clearFullPath = to.meta.clearFullPath;
	};
  store.commit('UPDATE_TABS', routerObject);
	if (!store.state.user.token && to.path != '/login') {
		router.push('/login');
		return;
	};

	next();


});


export default router
